package com.example.demo4.model

import java.io.Serializable

class Card(private var suit: String, private var rank: String, var isChosen:Boolean = false, var isMatched:Boolean = false) : Serializable {
    companion object {
        private const val serialVersionUID = 1L
        val rankStrings= arrayOf("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
        val validSuits = arrayOf("♥", "♦", "♠", "♣")
    }

    override fun toString(): String {
        return suit + rank
    }

    fun match(otherCards: Array<Card>): Int {
        var score = 0
        when (otherCards.size) {
            1 -> {
                // 2张牌匹配（保留原有逻辑）
                val otherCard = otherCards[0]
                if (otherCard.rank == rank) {
                    score = 4
                } else if (otherCard.suit == suit) {
                    score = 1
                }
            }
            2 -> {
                // 3张牌匹配：检查是否三张同花色
                val otherCard1 = otherCards[0]
                val otherCard2 = otherCards[1]
                if (this.suit == otherCard1.suit && this.suit == otherCard2.suit) {
                    // 三张同花色，匹配成功
                    score = 4
                }
            }
        }
        return score
    }
}

